export default function loadAMap (plugins) {
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      resolve(window.AMap)
    } else {
      var script = document.createElement('script')
      script.type = 'text/javascript'
      script.async = true
      script.src = '//webapi.amap.com/maps?v=1.4.15&key=2407131e760f934a99b18e675b358e07&callback=onAMapCallback'
      if (plugins) script.src += '&plugin=' + plugins.join(',')
      script.onerror = reject
      document.head.appendChild(script)
    }
    window.onAMapCallback = () => {
      resolve(window.AMap)
    }
  })
}
